<template>
  <div>
    <h2>房号添加</h2>
    <hr />
    <table>
      <tr>
        <td align="right">房号:</td>
        <td>
          <input type="text" v-model="state.name" />
        </td>
      </tr>
      <tr>
        <td align="right">创建人姓名:</td>
        <td>
          <input type="text" v-model="state.cName" />
        </td>
      </tr>
      <tr>
        <td align="right">
          <input type="button" value="添加" @click="FangHaoAdd" />
        </td>
        <td>
          <input type="button" value="列表" @click="FangHaoShow" />
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import axios from 'axios';

const router = useRouter();
const route = useRoute();

let data: any = reactive({
  state: {
    name: '',
    cName: '',
    zt: '1',
  },
});
let { state } = toRefs(data);

function FangHaoAdd() {
  let obj = {
    name: state.value.name,
    cName: state.value.cName,
    zt: state.value.zt
  };
  axios({
    url: 'https://localhost:7145/api/FangHao/FangHaoAdd',
    method: 'post',
    data: obj,
  })
    .then((res) => {
      
      if (res.data.data > 0) {
        alert('添加成功');
        router.push('/FangHaoShow');
      } else {
        alert('添加失败');
        return;
      }
    })
    .catch((err) => {
      console.log(err);
    });
}

function FangHaoShow(){
  router.push('/FangHaoShow');
}
</script>

<style scoped></style>
